<template>
  <div class="page-container" v-global-loading="loading">
    <div class="page-card-container">
      <a-tabs
        v-model:activeKey="activeKey"
        @change="changeTab"
        v-if="pageType == 2"
      >
        <a-tab-pane :key="1" tab="待我审核"> </a-tab-pane>
        <a-tab-pane :key="2" tab="我已审核"> </a-tab-pane>
        <a-tab-pane :key="3" tab="抄送于我"> </a-tab-pane>
      </a-tabs>
      <a-form :model="pageSet" layout="inline">
        <a-form-item label="客商名称  ">
          <a-input
            v-model:value="pageSet.customerName"
            style="width: 170px"
            :allowClear="true"
          ></a-input>
        </a-form-item>
        <a-form-item label="客户编码">
          <a-input
            v-model:value="pageSet.customerCode"
            style="width: 170px"
            :allowClear="true"
          ></a-input>
        </a-form-item>
        <a-form-item label="会员名称">
          <a-select
            v-model:value="pageSet.membersId"
            style="width: 200px"
            :filter-option="filterOption"
            show-search
          >
            <a-select-option
              :value="item.id"
              :title="item.name || ' '"
              v-for="item in membersinfo"
            >
              <div style="display: flex">
                <span style="min-width: 70px">{{ item.name }} </span>
                <span>{{ item.phone }}</span>
              </div>
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="集团名称">
          <a-input
            v-model:value="pageSet.parentCompany"
            style="width: 170px"
            :allowClear="true"
          ></a-input>
        </a-form-item>
        <a-form-item label="手机号">
          <a-input
            v-model:value="pageSet.phone"
            style="width: 170px"
            :allowClear="true"
          ></a-input>
        </a-form-item>
        <a-form-item label="审批状态">
          <a-select
            v-model:value="pageSet.applyStatus"
            style="width: 130px"
            :filter-option="filterOption"
            show-search
          >
            <a-select-option :value="0" title="待提交审批"
              >待提交审批</a-select-option
            >
            <a-select-option :value="1" title="审核中">审核中</a-select-option>
            <a-select-option :value="2" title="审核驳回"
              >审核驳回</a-select-option
            >
            <a-select-option :value="3" title="撤回">撤回</a-select-option>
            <a-select-option :value="9" title="审核通过"
              >审核通过</a-select-option
            >
          </a-select>
        </a-form-item>
        <a-form-item label="">
          <div class="commonBtn-warning" @click="loadPagination(true)">
            查询
          </div>
        </a-form-item>
        <a-form-item label="">
          <div class="commonBtn-primary" @click="reset">重置</div>
        </a-form-item>
        <a-form-item label="" v-if="pageType == 1">
          <div class="commonBtn-primary" @click="submit(1)">导入主体信息</div>
        </a-form-item>
        <a-form-item label="" v-if="pageType == 1">
          <div class="commonBtn-primary" @click="submit(4)">导出主体信息</div>
        </a-form-item>
      </a-form>

      <a-table
        size="small"
        :loading="tableLoading"
        :dataSource="tableData"
        :columns="columns"
        bordered
        :pagination="false"
        :scroll="{
          x: 1200,
          y: useAppStore.pageCommonInfo.canUseHeight - 36 + 'px'
        }"
      >
        <template #bodyCell="{text, record, index, column}">
          <template v-if="column.title == '客商名称'">
            <a-tooltip>
              <template #title>{{ text }}</template>
              <div class="font-left nowrap">{{ text }}</div>
            </a-tooltip>
          </template>
          <template v-if="column.title == '集团名称'">
            <a-tooltip>
              <template #title>{{ text }}</template>
              <div class="font-left nowrap">{{ text }}</div>
            </a-tooltip>
          </template>
          <template v-if="column.title == '客商注册人详细地址'">
            <a-tooltip>
              <template #title>{{ text }}</template>
              <div class="font-left nowrap">{{ text }}</div>
            </a-tooltip>
          </template>
          <template v-if="column.title == '开票行账号'">
            <a-tooltip>
              <template #title>{{ text }}</template>
              <div class="font-left nowrap">{{ text }}</div>
            </a-tooltip>
          </template>
          <template v-if="column.title == '自定义开票行银行名称'">
            <a-tooltip>
              <template #title>{{ text }}</template>
              <div class="font-left nowrap">{{ text }}</div>
            </a-tooltip>
          </template>
          <template v-if="column.title == '开票行账户名称'">
            <a-tooltip>
              <template #title>{{ text }}</template>
              <div class="font-left nowrap">{{ text }}</div>
            </a-tooltip>
          </template>
          <template v-if="column.title == '同步返回信息'">
            <a-tooltip>
              <template #title>{{ text }}</template>
              <div class="font-left nowrap">{{ text }}</div>
            </a-tooltip>
          </template>
          <template v-if="column.title == '操作'">
            <div>
              <span
                @click="operation(1, record)"
                onselectstart="return false"
                class="pointer c-primaryColor"
                >查看</span
              >
              <span
                onselectstart="return false"
                class="pointer c-primaryColor"
                v-if="pageType == 1 && record.applyStatus != 1"
                @click="operation(2, record)"
                >&nbsp;&nbsp;编辑</span
              >
              <span
                onselectstart="return false"
                class="pointer c-primaryColor"
                v-if="pageType == 2 && activeKey == 1"
                @click="operation(3, record)"
                >&nbsp;&nbsp;审核</span
              >
              <a-dropdown
                v-if="
                  (pageType == 1 && !record.isbloc) ||
                  (pageType == 1 &&
                    !record.isSys &&
                    record.applyStatus == 9 &&
                    !record.isAudit)
                "
              >
                <span class="pointer">&nbsp;&nbsp;更多<more-outlined /></span>
                <template #overlay>
                  <a-menu>
                    <a-menu-item key="1" v-if="pageType == 1 && !record.isbloc">
                      <span
                        onselectstart="return false"
                        class="pointer c-primaryColor"
                        @click="operation(4, record)"
                        >&nbsp;&nbsp;默认集团</span
                      >
                    </a-menu-item>
                    <a-menu-item
                      key="2"
                      v-if="
                        pageType == 1 &&
                        !record.isSys &&
                        record.applyStatus == 9 &&
                        !record.isAudit
                      "
                    >
                      <span
                        onselectstart="return false"
                        class="pointer c-primaryColor"
                        @click="operation(6, record)"
                        style="display: inline-block; min-width: 90px"
                        >&nbsp;&nbsp;同步企业主体</span
                      >
                    </a-menu-item>
                    <a-menu-item
                      key="3"
                      v-if="
                        (record.applyStatus == 9 && record.isAudit) ||
                        record.applyStatus == 0 ||
                        record.applyStatus == 3
                      "
                    >
                      <span
                        onselectstart="return false"
                        class="pointer c-primaryColor"
                        @click="operation(8, record)"
                        style="display: inline-block; min-width: 90px"
                        >&nbsp;&nbsp;删除</span
                      >
                    </a-menu-item>
                  </a-menu>
                </template>
              </a-dropdown>
            </div>
          </template>
          <template v-if="column.title == '审核状态'">
            <span
              onselectstart="return false"
              v-if="text == 0 || (record.isAudit && text == 9)"
              >待提交审批</span
            >
            <span
              onselectstart="return false"
              class="pointer c-primaryColor"
              v-else-if="text == 1"
              @click="operation(5, record)"
              >审核中</span
            >
            <span
              onselectstart="return false"
              class="pointer c-primaryColor"
              v-else-if="text == 2"
              @click="operation(5, record)"
              >审核驳回</span
            >
            <span onselectstart="return false" v-else-if="text == 3">撤回</span>
            <span
              onselectstart="return false"
              class="pointer c-primaryColor"
              v-else-if="text == 9 && record.approvalFlowId"
              @click="operation(5, record)"
              >审核通过</span
            >
            <span v-else onselectstart="return false">审核通过</span>
          </template>
          <template v-if="column.title == '状态'">
            <span class="color">{{ text }}</span>
          </template>
          <template v-if="column.title == '是否默认集团'">
            <span class="color">{{ text ? "是" : "否" }}</span>
          </template>
        </template>
      </a-table>
      <Pagination
        :pageSet="pageSet"
        style="margin-top: 10px"
        :loadPagination="loadPagination"
      ></Pagination>
      <a-modal
        v-model:open="visible"
        width="950px"
        :footer="null"
        :maskClosable="false"
        v-if="visible"
      >
        <a-tabs v-model:activeKey="activeKey2" @change="changeTab2">
          <a-tab-pane :key="1" tab="主体信息">
            <a-tabs v-model:activeKey="activeKey1">
              <a-tab-pane :key="1" tab="当前信息">
                <SubjectMessage
                  v-model:data="form"
                  @ok="subjectOk"
                  :isUpdata="isUpdata"
                  :isHistory="false"
                  ref="SubjectMessageRef"
                >
                </SubjectMessage>
              </a-tab-pane>
              <a-tab-pane
                :key="2"
                tab="历史提交信息"
                v-if="form.enterpriseBodyRecordDto"
              >
                <SubjectMessage
                  :data="form.enterpriseBodyRecordDto"
                  :isUpdata="false"
                  :isHistory="true"
                >
                </SubjectMessage>
              </a-tab-pane>
              <a-tab-pane :key="3" tab="修改记录">
                <a-table
                  size="small"
                  :dataSource="form.enterpriseBodyUpdateLogDtos"
                  :columns="updateLogColumns"
                  bordered
                  :pagination="false"
                >
                  <template #bodyCell="{text, record, index, column}">
                    <template v-if="column.title == '修改字段'">
                      <a-tooltip>
                        <template #title>{{ text }}</template>
                        <div class="font-left nowrap">{{ text }}</div>
                      </a-tooltip>
                    </template>
                    <template v-if="column.title == '操作'">
                      <div
                        style="cursor: pointer"
                        @click="operation(7, record)"
                      >
                        详情
                      </div>
                    </template>
                  </template>
                </a-table>
              </a-tab-pane>
            </a-tabs>
          </a-tab-pane>
          <a-tab-pane
            :key="2"
            tab="审批流程"
            v-if="
              ((form.applyStatus != 0 &&
                form.applyStatus != 3 &&
                form.applyStatus != 9) ||
                (form.applyStatus == 9 && !form.isAudit)) &&
              form.approvalFlowId
            "
          >
            <ExamineApprove
              :parameter="form"
              ref="ExamineApproveRef"
              @ok="approveOk"
            ></ExamineApprove>
          </a-tab-pane>
          <a-tab-pane
            :key="3"
            tab="审批流程图"
            v-if="
              ((form.applyStatus != 0 &&
                form.applyStatus != 3 &&
                form.applyStatus != 9) ||
                (form.applyStatus == 9 && !form.isAudit)) &&
              form.approvalFlowId
            "
          >
            <div v-global-loading="loadingFlowNode" style="position: relative">
              <div
                style="
                  opacity: 0;
                  position: absolute;
                  width: 100%;
                  height: 100%;
                  z-index: 999;
                "
              ></div>
              <FlowNode v-model:node="designContent"></FlowNode>
            </div>
          </a-tab-pane>
        </a-tabs>
      </a-modal>
      <!-- 导入主体信息 -->
      <a-modal
        v-model:open="visible1"
        width="500px"
        title="导入主体信息"
        :footer="null"
        :maskClosable="false"
      >
        <div v-global-loading="modalloading">
          <a-form :labelCol="{span: 7}">
            <a-form-item label="下载导入模板">
              <a
                href="https://kacunchu001.obs.cn-east-3.myhuaweicloud.com/dongcheng/file/%E5%AE%A2%E6%88%B7%E6%A1%A3%E6%A1%88%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF1700205193565ywetomqr.xls"
                >点击下载导入模板</a
              >
            </a-form-item>
            <a-form-item label="是否为SAP老客户" :labelCol="{span: 7}">
              <a-select v-model:value="importData.isSap" style="width: 130px">
                <a-select-option :value="true">是</a-select-option>
                <a-select-option :value="false">否</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="直接上传" :labelCol="{span: 7}">
              <div style="display: flex; line-height: 30px; flex-wrap: wrap">
                <span style="width: 250px">{{ importData.name }}</span>
                <div
                  class="commonBtn-primary"
                  @click="submit(2)"
                  style="min-width: 90px"
                >
                  文件上传
                </div>
              </div>
            </a-form-item>
          </a-form>
          <div style="display: flex; justify-content: end">
            <a-button style="margin-right: 14px" @click="visible1 = false"
              >取消</a-button
            >
            <a-button type="primary" @click="submit(3)">确定</a-button>
          </div>
        </div>
      </a-modal>
      <!-- 订单错误信息 -->
      <a-modal
        v-model:open="visible2"
        width="1000px"
        title="主体信息导入结果"
        :footer="null"
        :maskClosable="false"
        @cancel="loadPagination(true)"
      >
        <a-alert
          message="部分主体信息未导入成功，请检查之后重新上传导入失败的信息。"
          type="warning"
          show-icon
          v-if="returnMessage.isMatchError"
        />
        <div v-if="returnMessage.rightEnterprises.length != 0">
          <div
            style="
              margin-bottom: 10px;
              display: flex;
              justify-content: space-between;
            "
          >
            <span style="font-size: 16px; font-weight: 800"
              >成功导入的信息：</span
            >
            <div class="commonBtn-primary" @click="exportDerive(1)">导出</div>
          </div>
          <a-table
            size="small"
            :dataSource="returnMessage.rightEnterprises"
            :columns="succeedMessage(1)"
            bordered
            :pagination="false"
            :scroll="{
              x: 800,
              y: 500
            }"
          >
          </a-table>
        </div>
        <div v-if="returnMessage.errorEnterprises.length != 0">
          <div
            style="
              margin: 10px 0px;
              display: flex;
              justify-content: space-between;
            "
          >
            <span style="font-size: 16px; font-weight: 800"
              >导入失败的信息：</span
            >
            <div class="commonBtn-primary" @click="exportDerive(2)">导出</div>
          </div>
          <a-table
            size="small"
            :dataSource="returnMessage.errorEnterprises"
            :columns="succeedMessage(2)"
            bordered
            :pagination="false"
            :scroll="{
              x: 800,
              y: 500
            }"
          >
          </a-table>
        </div>
      </a-modal>

      <!-- 修改记录详情 -->
      <a-modal
        v-model:open="visible3"
        width="1000px"
        title="详情"
        :footer="null"
        :maskClosable="false"
        @cancel="close3"
        zIndex="6000"
      >
        <a-table
          size="small"
          :dataSource="updateLogDetail"
          :columns="updateLogDetailColumns"
          bordered
          :pagination="false"
        ></a-table>
      </a-modal>
    </div>
  </div>
</template>

<script lang="ts" setup>
import {ref, computed, inject, onActivated, onMounted} from "vue";
import {trigerUpload, exportData} from "@/utils/common";
import Pagination from "@/components/pagination/Pagination.vue";
import useAppStore from "@/store/app";
import {exportExcel} from "@/utils/exportFile";
import ExamineApprove from "@/components/functional/ExamineApprove.vue";
import SubjectMessage from "@/components/customerArchives/SubjectMessage.vue";
import FlowNode from "@/components/flow/FlowNode.vue";
import {
  enterpriseBodyUpdate,
  enterpriseBodyPage,
  enterpriseBodyList,
  enterpriseBodyDetail,
  enterpriseBodySetBloc,
  enterpriseBodyChangeApplyStatus,
  enterpriseBodyCheckPage,
  enterpriseBodyMembersinfo,
  enterpriseBodySynSAP,
  enterpriseBodyImportEnterprise,
  enterpriseBodyExportEnterpriseBody,
  enterpriseBodyDelete
} from "@/api/customerArchives/subjectMessage";
import {flowdesignDetail} from "@/api/configCenter/platform/processTemplate";
import {message, Modal} from "ant-design-vue";
const calcCanUseHeight: any = inject("calcCanUseHeight");
const filterOption = (input: string, option: any) => {
  return option.title.toLowerCase().indexOf(input.toLowerCase()) >= 0;
};
onActivated(() => {
  calcCanUseHeight();
});
onMounted(() => {
  calcCanUseHeight();
});
//导出主体信息
const visible1 = ref(false);
const visible2 = ref(false);
const modalloading = ref(false);
const importData: any = ref({});
const returnMessage: any = ref({errorEnterprises: [], rightEnterprises: []});
const submit = (type) => {
  if (type == 1) {
    importData.value = {isSap: true};
    visible1.value = true;
  } else if (type == 2) {
    trigerUpload().then((res: any) => {
      let files = res.target.files[0];
      if (
        files.type ==
          "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ||
        files.type == "application/vnd.ms-excel"
      ) {
        let formData = new FormData();
        formData.append("file", files);
        formData.append("isSap", importData.value.isSap);
        importData.value.file = formData;
        importData.value.name = files.name;
      } else {
        message.error("请上传xls、xslx类型的文件！");
      }
    });
  } else if (type == 3) {
    if (importData.value.file) {
      modalloading.value = true;
      enterpriseBodyImportEnterprise(importData.value.file)
        .then((res) => {
          visible1.value = false;
          visible2.value = true;
          returnMessage.value = res.data;
        })
        .finally(() => {
          modalloading.value = false;
        });
    } else {
      message.error("请先上传文件!");
    }
  } else if (type == 4) {
    //导出主体信息
    loading.value = true;
    enterpriseBodyExportEnterpriseBody(pageSet.value)
      .then((res) => {
        exportData(res, "主体信息");
      })
      .finally(() => {
        loading.value = false;
      });
  }
};
const exportDerive = (type): void => {
  if (type == 1) {
    let arr = JSON.parse(JSON.stringify(returnMessage.value.rightEnterprises));
    arr.forEach((item) => {
      if (item.invoiceType == "Z5") {
        item.invoiceType = "数电增值税专票";
      } else if (item.invoiceType == "Z6") {
        item.invoiceType = "数电增值税普票";
      } else if (item.invoiceType == "Z1") {
        item.invoiceType = "增值税专用发票";
      } else if (item.invoiceType == "Z3") {
        item.invoiceType = "增值税电子普通发票";
      }
    });
    exportExcel(succeedMessage(1), arr, "成功导入的信息");
  } else if (type == 2) {
    let arr = JSON.parse(JSON.stringify(returnMessage.value.errorEnterprises));
    arr.forEach((item) => {
      if (item.invoiceType == "Z5") {
        item.invoiceType = "数电增值税专票";
      } else if (item.invoiceType == "Z6") {
        item.invoiceType = "数电增值税普票";
      } else if (item.invoiceType == "Z1") {
        item.invoiceType = "增值税专用发票";
      } else if (item.invoiceType == "Z3") {
        item.invoiceType = "增值税电子普通发票";
      }
    });
    exportExcel(succeedMessage(2), arr, "导入失败的信息");
  }
};
const membersinfo = ref<Array<any>>([]);
const getMembersinfo = () => {
  enterpriseBodyMembersinfo().then((res) => {
    membersinfo.value = res.data;
  });
};
getMembersinfo();
const loadingFlowNode = ref(false);
const tableData = ref<Array<object>>([]);
const activeKey = ref(1);
const visible = ref<boolean>(false);
const form = ref<any>({});
const SubjectMessageRef = ref();
const ExamineApproveRef = ref();
const activeKey1 = ref(1);
const activeKey2 = ref(1);
const subjectOk = (data, flag) => {
  if (data) {
    //编辑
    if (form.value.isAudit) {
      if (flag) {
        //保存
        form.value.applyStatus = 0;
      } else {
        //提交
        form.value.applyStatus = 1;
      }
    }
    SubjectMessageRef.value.modalloading = true;
    enterpriseBodyUpdate(form.value)
      .then(() => {
        if (form.value.isAudit) {
          if (flag) {
            message.success("保存成功!");
          } else {
            message.success("提交成功!");
          }
        }
        loadPagination();
        setTimeout(() => {
          visible.value = false;
        }, 200);
      })
      .finally(() => {
        SubjectMessageRef.value.modalloading = false;
      });
  } else {
    //取消
    visible.value = false;
  }
};
const approveOk = (data) => {
  let dataList = {
    id: data.id,
    businessType: 200,
    approvalFlowId: data.approvalFlowId,
    nodeId: data.nodeId,
    bizCheckOperationType: data.type,
    remark: data.remark
  };
  ExamineApproveRef.value.loading = true;
  enterpriseBodyChangeApplyStatus(dataList)
    .then(() => {
      message.success("审核成功!");
      loadPagination(false);
      ExamineApproveRef.value.loading = false;
      visible.value = false;
    })
    .catch(() => {
      ExamineApproveRef.value.loading = false;
    });
};
//是否已经访问过
const interview = ref({
  a: false,
  b: false
});
const designContent = ref();
const changeTab2 = (e) => {
  if (e == 2) {
    if (!interview.value.a) {
      setTimeout(() => {
        ExamineApproveRef.value.showModal();
        interview.value.a = true;
      }, 500);
    }
  } else if (e == 3) {
    if (!interview.value.b) {
      loadingFlowNode.value = true;
      flowdesignDetail({id: form.value.flowDesignId})
        .then((res) => {
          designContent.value = JSON.parse(res.data.designContent);
        })
        .finally(() => {
          loadingFlowNode.value = false;
        });
      interview.value.b = true;
    }
  }
};
// 修改日志信息
const visible3 = ref<boolean>(false);
const updateLogDetail = ref([]);
const close3 = () => {
  visible3.value = false;
  updateLogDetail.value = [];
};

//是否是编辑
const isUpdata = ref(false);
//操作
const operation = (type: number, e: any) => {
  if (type == 1) {
    //查看
    useAppStore.loading = true;
    enterpriseBodyDetail({id: e.id})
      .then((res) => {
        form.value = res.data;
        form.value.examine = false;
        isUpdata.value = false;
        visible.value = true;
        interview.value = {
          a: false,
          b: false
        };
        activeKey1.value = 1;
        activeKey2.value = 1;
      })
      .finally(() => {
        useAppStore.loading = false;
      });
  } else if (type == 2) {
    //编辑
    useAppStore.loading = true;
    enterpriseBodyDetail({id: e.id})
      .then((res) => {
        form.value = res.data;
        form.value.examine = false;
        isUpdata.value = true;
        visible.value = true;
        interview.value = {
          a: false,
          b: false
        };
        activeKey1.value = 1;
        activeKey2.value = 1;
      })
      .finally(() => {
        useAppStore.loading = false;
      });
  } else if (type == 3) {
    //审核
    useAppStore.loading = true;
    enterpriseBodyDetail({id: e.id})
      .then((res) => {
        form.value = res.data;
        form.value.examine = true;
        isUpdata.value = false;
        visible.value = true;
        interview.value = {
          a: false,
          b: false
        };
        activeKey1.value = 1;
        activeKey2.value = 2;
        changeTab2(2);
      })
      .finally(() => {
        useAppStore.loading = false;
      });
  } else if (type == 4) {
    //默认集团
    Modal.confirm({
      title: "提示",
      content: "确定要设置为默认集团吗？",
      onOk() {
        useAppStore.loading = true;
        enterpriseBodySetBloc({id: e.id})
          .then((res) => {
            message.success("设置成功！");
            loadPagination();
          })
          .finally(() => {
            useAppStore.loading = false;
          });
      }
    });
  } else if (type == 5) {
    //查看流转状态
    useAppStore.loading = true;
    enterpriseBodyDetail({id: e.id})
      .then((res) => {
        form.value = res.data;
        form.value.examine = false;
        isUpdata.value = false;
        visible.value = true;
        interview.value = {
          a: false,
          b: false
        };
        activeKey1.value = 1;
        activeKey2.value = 2;
        changeTab2(2);
      })
      .finally(() => {
        useAppStore.loading = false;
      });
  } else if (type == 6) {
    //同步主体信息
    Modal.confirm({
      title: "提示",
      content: "确定要同步该主体信息吗？",
      onOk() {
        useAppStore.loading = true;
        enterpriseBodySynSAP({id: e.id})
          .then((res) => {
            // if (res.data.split("成功").length >= 2) {
            //   message.success("同步成功");
            // } else {
            //   message.error("同步失败");
            // }
            message.warning(res.data);
            loadPagination();
          })
          .finally(() => {
            useAppStore.loading = false;
          });
      }
    });
  } else if (type == 7) {
    updateLogDetail.value = e.updateDetail ? JSON.parse(e.updateDetail) : [];
    visible3.value = true;
  } else if (type == 8) {
    Modal.confirm({
      title: "提示",
      content: "确定要删除吗？",
      onOk() {
        useAppStore.loading = true;
        enterpriseBodyDelete({id: e.id})
          .then((res) => {
            message.success("删除成功！");
            loadPagination();
          })
          .finally(() => {
            useAppStore.loading = false;
          });
      }
    });
  }
};
const changeTab = (e) => {
  activeKey.value = e;
  pageSet.value = {
    pageNo: 1,
    pageSize: 20,
    total: 0,
    checkType: activeKey.value
  };
  loadPagination(true);
};
const props = defineProps({
  type: {
    type: Number,
    default: 1
  }
});
const pageType = computed({
  get() {
    return props.type;
  },
  set() {}
});
const tableLoading = ref<boolean>(false);
const loading = ref<boolean>(false);
const pageSet: any = ref({
  pageNo: 1,
  pageSize: 20,
  total: 0,
  checkType: activeKey.value
});
//获取数据
const loadPagination = (flag: boolean = false): void => {
  if (flag) {
    pageSet.value.pageNo = 1;
  }
  tableLoading.value = true;
  if (pageType.value == 1) {
    enterpriseBodyPage(pageSet.value)
      .then((res) => {
        tableData.value = res.data.rows;
        pageSet.value.total = res.data.totalRows;
      })
      .finally(() => {
        tableLoading.value = false;
      });
  } else {
    enterpriseBodyCheckPage(pageSet.value)
      .then((res) => {
        tableData.value = res.data.rows;
        pageSet.value.total = res.data.totalRows;
      })
      .finally(() => {
        tableLoading.value = false;
      });
  }
};
loadPagination(true);
//重置
const reset = (): void => {
  pageSet.value = {
    pageNo: 1,
    pageSize: 20,
    total: 0,
    checkType: activeKey.value
  };
  loadPagination(true);
};
const columns = ref<Array<object>>([
  {
    title: "序号",
    dataIndex: "name",
    align: "center",
    width: 50,
    customRender: ({index}) => {
      return index + 1;
    },
    fixed: "left"
  },
  {
    title: "客商名称",
    dataIndex: "customerName",
    align: "center",
    width: 200
  },
  {
    title: "集团名称",
    dataIndex: "parentCompany",
    align: "center",
    width: 200
  },
  {
    title: "客户编码",
    dataIndex: "customerCode",
    align: "center",
    width: 120
  },
  {
    title: "统一社会信用代码",
    dataIndex: "creditCode",
    align: "center",
    width: 170
  },
  {
    title: "客商注册人详细地址",
    dataIndex: "address",
    align: "center",
    width: 250
  },
  {
    title: "电话",
    dataIndex: "tel",
    align: "center",
    width: 120
  },
  {
    title: "手机号",
    dataIndex: "phone",
    align: "center",
    width: 120
  },
  {
    title: "邮箱",
    dataIndex: "email",
    align: "center",
    width: 180
  },
  {
    title: "发票种类",
    dataIndex: "invoiceType",
    align: "center",
    width: 150,
    customRender: ({value}) => {
      if (value == "Z5") {
        return "数电增值税专票";
      } else if (value == "Z6") {
        return "数电增值税普票";
      } else if (value == "Z1") {
        return "增值税专用发票";
      } else if (value == "Z3") {
        return "增值税电子普通发票";
      }
    }
  },
  {
    title: "银行序号",
    dataIndex: "bankNum",
    align: "center",
    width: 120
  },
  {
    title: "开票行银行代码",
    dataIndex: "bankCode",
    align: "center",
    width: 150
  },
  {
    title: "开票行账户名称",
    dataIndex: "accountName",
    align: "center",
    width: 200
  },
  {
    title: "自定义开票行银行名称",
    dataIndex: "bankName",
    align: "center",
    width: 200
  },
  {
    title: "开票行账号",
    dataIndex: "bankAccount",
    align: "center",
    width: 180
  },
  {
    title: "授信额度",
    dataIndex: "creditLine",
    align: "center",
    width: 120
  },
  {
    title: "同步SAP时间",
    dataIndex: "sysDate",
    align: "center",
    width: 180
  },
  {
    title: "是否默认集团",
    dataIndex: "isbloc",
    align: "center",
    width: 120
  },
  {
    title: "同步返回信息",
    dataIndex: "sysReturnRes",
    align: "center",
    width: 180
  },
  {
    title: "是否SAP老客户",
    dataIndex: "isSAP",
    align: "center",
    width: 120,
    fixed: "right",
    customRender: ({value}) => {
      if (value) {
        return "是";
      } else {
        return "否";
      }
    }
  },
  {
    title: "同步结果",
    dataIndex: "isSys",
    align: "center",
    width: 80,
    fixed: "right",
    customRender: ({value}) => {
      if (value) {
        return "已同步";
      } else {
        return "未同步";
      }
    }
  },
  {
    title: "审核状态",
    dataIndex: "applyStatus",
    align: "center",
    width: 100,
    fixed: "right"
  },
  {
    title: "操作",
    dataIndex: "u",
    align: "center",
    width: 140,
    fixed: "right"
  }
]);
const succeedMessage = (type) => {
  let columnsMessage = [
    {
      title: "序号",
      dataIndex: "name",
      align: "center",
      width: 50,
      customRender: ({index}) => {
        return index + 1;
      },
      fixed: "left"
    },
    {
      title: "会员账号",
      dataIndex: "memberAccount",
      align: "center",
      width: 200
    },
    {
      title: "SAP客户代码",
      dataIndex: "customerCode",
      align: "center",
      width: 200
    },
    {
      title: "客商名称",
      dataIndex: "customerName",
      align: "center",
      width: 200
    },
    {
      title: "统一社会信用代码",
      dataIndex: "creditCode",
      align: "center",
      width: 170
    },
    {
      title: "部门",
      dataIndex: "legalPerson",
      align: "center",
      width: 170
    },
    {
      title: "电话",
      dataIndex: "tel",
      align: "center",
      width: 120
    },
    {
      title: "手机号",
      dataIndex: "phone",
      align: "center",
      width: 120
    },
    {
      title: "邮箱",
      dataIndex: "email",
      align: "center",
      width: 180
    },
    {
      title: "发票种类",
      dataIndex: "invoiceType",
      align: "center",
      width: 150,
      customRender: ({value}) => {
        if (value == "Z5") {
          return "数电增值税专票";
        } else if (value == "Z6") {
          return "数电增值税普票";
        } else if (value == "Z1") {
          return "增值税专用发票";
        } else if (value == "Z3") {
          return "增值税电子普通发票";
        }
      }
    },
    {
      title: "银行序号",
      dataIndex: "bankNum",
      align: "center",
      width: 120
    },
    {
      title: "开票行银行代码",
      dataIndex: "bankCode",
      align: "center",
      width: 150
    },
    {
      title: "开票行账户名称",
      dataIndex: "accountName",
      align: "center",
      width: 150
    },
    {
      title: "开票行账号",
      dataIndex: "bankAccount",
      align: "center",
      width: 180
    },
    {
      title: "自定义开票行银行名称",
      dataIndex: "bankName",
      align: "center",
      width: 180
    },
    {
      title: "客商注册地所属省",
      dataIndex: "province",
      align: "center",
      width: 150
    },
    {
      title: "客商注册地所属市",
      dataIndex: "city",
      align: "center",
      width: 150
    },
    {
      title: "客商注册地所属县",
      dataIndex: "county",
      align: "center",
      width: 180
    },
    {
      title: "客商详细地址",
      dataIndex: "address",
      align: "center",
      width: 150
    },
    {
      title: "是否为默认集团",
      dataIndex: "isbloc",
      align: "center",
      width: 120
    },
    {
      title: "错误信息",
      dataIndex: "errorMsg",
      align: "center",
      width: 200,
      fixed: "right"
    }
  ];
  if (type == 1) {
    //正确
    return columnsMessage.filter((item) => {
      return item.title != "错误信息";
    });
  } else {
    return columnsMessage;
  }
};
const updateLogColumns = ref([
  {
    title: "修改人",
    dataIndex: "userName",
    align: "center",
    width: 120
  },
  {
    title: "修改字段",
    dataIndex: "content",
    align: "center",
    width: 200
  },
  {
    title: "修改时间",
    dataIndex: "createdTime",
    align: "center",
    width: 120
  },
  {
    title: "操作",
    dataIndex: "options",
    align: "center",
    width: 120
  }
]);
const updateLogDetailColumns = ref([
  {
    title: "修改字段",
    dataIndex: "FieldName",
    align: "center",
    width: 120
  },
  {
    title: "修改前值",
    dataIndex: "OldData",
    align: "center",
    width: 120
  },
  {
    title: "修改后值",
    dataIndex: "NewData",
    align: "center",
    width: 120
  }
]);
</script>

<style lang="less" scoped>
.color {
  color: rgb(2, 167, 240);
}
</style>
